package main

import (
	"os/signal"
	"server/src/logging"
	"syscall"

	"os"
)

const VER string = "数据推送服务器 v1.0 build 200827"

func main() {
	var err error
	var targetName string

	initGlobal()

	// 启动日志
	logging.DisableBootScreenLog()
	logging.LogBoot()

	zLog(nil, VER, " 启动")

	cfg, err := loadConfig("")
	if err != nil {
		zLog(nil, err.Error())
		return
	}

	if cfg.TeamName != "" {
		targetName = cfg.TeamName
	} else {
		targetName = cfg.CompanyName
	}

	zLog(nil, targetName, VER, " 启动")

	dbo, err := NewDBOperation(cfg)
	if err != nil {
		zLog(nil, "数据库连接失败，程序退出:", err)
		return
	} else {
		zLog(nil, "数据库连接成功")
	}
	defer dbo.Close()

	NewProcessor(dbo, cfg).Run()

	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

	s := <-signalChan
	zLog(nil, targetName, VER, "收到退出信号:", s)
}
